import '../sass/common.scss';
import * as tools from './tools';
jQuery.support.cors = true;
$(function(){
    $('input').on('blur', function (event) {
        let trg = event.target;
        tools.checkInput(trg)
    });

    //处理提交最后一次校验
    $('.handleSubmit').click(function() {
        let inputs = $('input[id]');
        let result = true;
        for(let i = 0; i < inputs.length - 1; i++) {
            result = tools.checkInput(inputs[i])
        }
        if(!result) return
        login();
    });

    var slider = new SliderUnlock("#slider",{
        successLabelTip : "验证成功" 
    },function(){
        $('.handleSubmit').removeClass('disabled')
    });
    slider.init();
})

function login() {

    $.ajax({
        url : tools.apiUrl + 'user/loginManager',
        type : 'post',
        data : {
            name : $('#loginName').val(),
            password : $('#password').val()
        },
        success : function(res) {
            if(res.code == 200) {
                tools.setLoginInfo(res.data);
                let url = sessionStorage.getItem('loginPage');
                if(url == 'video') {
                    location.href = './vedio.html';
                }else {
                    location.href = tools.loginUrl + res.data.sessionID ;
                }
            } else alert('请输入正确的账号或密码！！！');
        }
    })
}

$('[data-toggle="tooltip"]').tooltip()